package cn.enjoyedu.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 类说明：
 */
@Controller
@RequestMapping("/kafka")
public class KafkaController {

    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;


    @ResponseBody
    @RequestMapping("spring")
    public String queueSender(@RequestParam("message") String message) {
        String opt = "";
        try {
            kafkaTemplate.send("kafka-spring-topic", message);
            opt = "suc";
        } catch (Exception e) {
            opt = e.getCause().toString();
        }
        return opt;
    }


    @ResponseBody
    @RequestMapping("springb")
    public String topicSender(@RequestParam("message") String message) {
        String opt = "";
        try {
            kafkaTemplate.send("kafka-spring-topic-b", message);
            opt = "suc";
        } catch (Exception e) {
            opt = e.getCause().toString();
        }
        return opt;
    }

}
